package Controllers;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import Entities.CreateMarketingPatternEntity;
import Entities.InsertProductDetailsEntity;
import Entities.SendPermissionRequestEntity;
import GUI.CreateMarketingPatternGUI;
import GUI.InsertProductDetailsGUI;
import GUI.MarketingEmployeeGUI;
import GUI.SendPermissionRequestGUI;

/**
 * The Class MarketingEmployeeController.
 * Controller for marketing employee activities.
 */
public class MarketingEmployeeController {
	
	/** The marketing employee gui. */
	private MarketingEmployeeGUI marketingEmployeeGui;
	
	/** The previous panel. */
	private MarketingManagerController prev;
	
	/** The access. */
	private int access;
	
	/**
	 * Instantiates a new marketing employee controller.
	 *
	 * @param marketingEmployeeGui the marketing employee gui
	 * @param access separates between marketing employee and marketing manager
	 */
	public MarketingEmployeeController(MarketingEmployeeGUI marketingEmployeeGui,int access) {
		this.marketingEmployeeGui = marketingEmployeeGui;
		this.access = access;
		
		this.marketingEmployeeGui.addSendPermissionRequestActionListener(new SendPermissionRequestListener());
		this.marketingEmployeeGui.addInsertProductDetailsActionListener(new InsertProductDetailsListener());
		this.marketingEmployeeGui.addDefineMarketingPatternsActionListener(new defineMarketingPatternsListener());
		this.marketingEmployeeGui.addComputeRanksActionListener(new computeRanksListener());
		this.marketingEmployeeGui.addBackActionListener(new BackListener());
		if(access!=1)
			this.marketingEmployeeGui.getBtnBack().setVisible(false);
	}
	
	
	/**
	 * SendPermissionRequestListener class implements ActionListener interface.
	 * this class controls the sendPermission button.
	 *
	 * @see SendPermissionRequestEvent
	 */
	class SendPermissionRequestListener implements ActionListener
	{
		
		/* (non-Javadoc)
		 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
		 */
		@Override
		public void actionPerformed(ActionEvent e) {
				SendPermissionRequestGUI sendPermissionRequestGUI=new SendPermissionRequestGUI();
				new SendPermissionRequestController(sendPermissionRequestGUI,new SendPermissionRequestEntity()).setPrev(MarketingEmployeeController.this);
				LoginController.mainWindow.setContentPane(sendPermissionRequestGUI);
			LoginController.mainWindow.setTitle("Send Permission Request");
		}

	}
	
	/**
	 * InsertProductDetailsListener class implements ActionListener interface.
	 * this class controls the InsertProductDetails button.
	 *
	 * @see InsertProductDetailsEvent
	 */
	class InsertProductDetailsListener implements ActionListener
	{
		
		/* (non-Javadoc)
		 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
		 */
		@Override
		public void actionPerformed(ActionEvent e) {
			InsertProductDetailsGUI insertProductDetailsGUI=new InsertProductDetailsGUI();
			new InsertProductDetailsController(insertProductDetailsGUI,new InsertProductDetailsEntity()).setPrev(MarketingEmployeeController.this);
			LoginController.mainWindow.setContentPane(insertProductDetailsGUI);
			LoginController.mainWindow.setTitle("Insert new product");
		}

	}
	
	/**
	 * defineMarketingPatternsListener class implements ActionListener interface.
	 * this class controls the defineMarketingPatterns button.
	 *
	 * @see defineMarketingPatternsEvent
	 */
	class defineMarketingPatternsListener implements ActionListener
	{

		/* (non-Javadoc)
		 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
		 */
		@Override
		public void actionPerformed(ActionEvent e) {
			CreateMarketingPatternGUI createMarketingPatternGui=new CreateMarketingPatternGUI();
			new CreateMarketingPatternController(createMarketingPatternGui,new CreateMarketingPatternEntity()).setPrev(MarketingEmployeeController.this);
			LoginController.mainWindow.setContentPane(createMarketingPatternGui);
			LoginController.mainWindow.setTitle("Create marketing pattern");
		}
		
	}
	
	/**
	 * computeRanksListener class implements ActionListener interface.
	 * this class controls the computeRanks button.
	 *
	 * @see computeRanksEvent
	 */
	class computeRanksListener implements ActionListener
	{

		/* (non-Javadoc)
		 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
		 */
		@Override
		public void actionPerformed(ActionEvent e) {
			new ComputeRanksController(marketingEmployeeGui).calculateRanks();
		}
		
	}
	
	/**
	 * BackListener class implements ActionListener interface.
	 * this class controls the back button.
	 *
	 * @see BackEvent
	 */
	class BackListener implements ActionListener
	{

		/* (non-Javadoc)
		 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
		 */
		@Override
		public void actionPerformed(ActionEvent e) {
			if(access==1)
			LoginController.mainWindow.setContentPane(prev.getMarketingManagerGui());
		}
	}
	
	/**
	 * Gets the marketing employee gui.
	 *
	 * @return the marketing employee gui
	 */
	public MarketingEmployeeGUI getMarketingEmployeeGui() {
		return marketingEmployeeGui;
	}

	/**
	 * Sets the prev window.
	 *
	 * @param prev the new prev
	 */
	public void setPrev(MarketingManagerController prev) {
		this.prev = prev;
	}
}
